package com.os.opencv.java.chapter2;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;

public class SimpleMat {

    public static void main(String[] args) {
        //加载opencv用户库
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //创建简单的矩阵
        Mat m0 = Mat.zeros(2, 3, CvType.CV_8UC1);
        Mat m1 = Mat.ones(3, 2, CvType.CV_8UC1);
        Mat m2 = Mat.eye(3, 3, CvType.CV_8UC1);
        Mat m3 = Mat.ones(2, 3, CvType.CV_8UC3);
        Mat m4 = Mat.ones(3,4, CvType.CV_8UC3);

        //在控制台输出矩阵m0的数据
        System.out.println("m0:");
        System.out.println(m0.dump());

        System.out.println("m1:");
        System.out.println(m1.dump());

        System.out.println("m2:");
        System.out.println(m2.dump());

        System.out.println("m3:");
        System.out.println(m3.dump());

        System.out.println("m4:");
        System.out.println(m4.dump());

        Mat m5 = Mat.ones(3, 3, CvType.CV_8UC1);
        Mat dst = new Mat();
        m5.copyTo(dst);
        System.out.println("dst:");
        System.out.println(dst.dump());

        Mat m6 = new Mat(2, 2, CvType.CV_8UC3, new Scalar(255, 255, 112));
        System.out.println("m6:");
        System.out.println(m6.dump());

        //通过读取图像文件创建mat对象
        ///Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/test.jpg
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/test.jpg");
        //HighGui.imshow("src", src);
        //HighGui.waitKey(0);

        //用mat类的clone方法创建
        Mat src1 = Mat.ones(3, 3, CvType.CV_8UC1);
        Mat dst1 = src1.clone();
        System.out.println("dst1:");
        System.out.println(dst1.dump());
    }
}
